package learn.up.java1.quartz;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobKey;
import org.quartz.TriggerKey;

public class JobHello implements Job {
	
	private Integer times;
	private Double value;

	public static SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	@Override
	public void execute(JobExecutionContext arg0) throws JobExecutionException {
//		编写具体业务逻辑
		System.out.println("helloworld performance at "+sfd.format(new Date()));
		
		JobKey key = arg0.getJobDetail().getKey();
		System.out.println("key  :"+key.getGroup()+"   "+key.getName());
		TriggerKey trKey  =  arg0.getTrigger().getKey();
		System.out.println("trkey  "+trKey.getGroup()+"   "+trKey.getName());
		
//		JobDataMap jdm1 = arg0.getJobDetail().getJobDataMap();
//		JobDataMap jdm2 = arg0.getTrigger().getJobDataMap();
		/*
		 * 多个JobDateMap可以融合成一个，一次性获取.若Trigger和JobDetail的DateMap
		有相同的key值，则混合后的trigger的key值会覆盖掉jobDetail的key值
		*/
		JobDataMap  jdm  = arg0.getMergedJobDataMap();
		Integer times = jdm.getInt("times");
		String info = jdm.getString("info");
		Double value = jdm.getDouble("value");
		
//		获取JobDateMap的第二种方法，通过设置三个key值同名的同类型的属性，以及setter方法，
//		然后可以在任务执行过程中直接获取
		System.out.println(times+"   "+info+"  "+value);
	}

	public Integer getTimes() {
		return times;
	}

	public void setTimes(Integer times) {
		this.times = times;
	}

	public Double getValue() {
		return value;
	}

	public void setValue(Double value) {
		this.value = value;
	}

}
